package com.easymall.service.impl;

import com.easymall.dao.ProdDao;
import com.easymall.domain.Prod;
import com.easymall.service.ProdService;
import com.easymall.util.BaseFactory;

import java.sql.SQLException;
import java.util.List;

public class ProdServiceImpl implements ProdService {

    private ProdDao prodDao;

    @Override
    public void init() throws Exception {
        prodDao = BaseFactory.getFactory().getInstance(ProdDao.class);
    }

    @Override
    public boolean saveProd(Prod prod) throws SQLException {
        return prodDao.saveProd(prod);
    }

    @Override
    public boolean deleteProd(int pid) throws SQLException {
        return prodDao.deleteProd(pid);
    }

    @Override
    public boolean hasProdById(int id) throws SQLException {
        Prod prod = prodDao.getProdById(id);
        if (null == prod){
            return false;
        }else {
            return true;
        }
    }

    @Override
    public Prod getProdById(int id) throws SQLException {
        return prodDao.getProdById(id);
    }

    @Override
    public List<Prod> listProdAll() throws SQLException {
        return prodDao.listProdAll();
    }
}
